Visit us at - https://github.com/supercoderz

pyeurofx

pyeurofx is a library that allows you to fetch the close prices of various majot currencies vs the Euro. The library provides simple functions that you can invoke and get the data as list of tuples or as pandas data frames.

pyeurofx makes use of the following libraries -

  • requests
  • lxml
  • pandas

The data is fetched from the following XML sources -


In [2]:
from eurofx import *

Daily data

You can get the daily data or the historical data. Daily data will be the close price released at 3 PM CET on that day or the prevvious day depending on when you are running the call. Historical close prices will be the close prices for all the days since 1 Apr 1999

The daily data is returned as a list of tuples - each tuple is a currency, date, rate pair.

daily = get_daily_data() print daily

Historical data

Fetching all the historical data is just one function call - the data is returned just like daily data in a list of tuples.


In [3]:
historical = get_historical_data()
print historical.__len__()


124398

The first date of historical data


In [4]:
print historical[-1:]


[('ZAR', datetime.date(1999, 1, 4), '6.9358')]

getting data as pandas data frame

you can easily get the data as a pandas data frame by using the _df versions of the daily and historical commands

Any date which has a missing data will show up as a NaN in pandas data frame.


In [5]:
daily_df = get_daily_data_df()
print daily_df


               USD     JPY     BGN     CZK     DKK      GBP     HUF     LTL  \
2014-07-25  1.3440  136.97  1.9558  27.482  7.4568  0.79115  308.06  3.4528   

               PLN     RON   ...       ILS      INR      KRW      MXN     MYR  \
2014-07-25  4.1435  4.3973   ...    4.6004  80.7677  1380.11  17.4162  4.2655   

               NZD     PHP     SGD     THB      ZAR  
2014-07-25  1.5728  58.199  1.6682  42.780  14.1489  

[1 rows x 32 columns]

In [6]:
historical_df = get_historical_data_df()
print historical_df.head()


               USD     JPY     BGN     CZK     DKK      GBP     HUF     LTL  \
2014-07-25   1.344  136.97  1.9558  27.482  7.4568  0.79115  308.06  3.4528   
2014-07-24  1.3472  136.97  1.9558   27.48  7.4573  0.79215  307.76  3.4528   
2014-07-23  1.3465  136.51  1.9558  27.454  7.4569   0.7908  307.15  3.4528   
2014-07-22  1.3481  136.93  1.9558  27.485  7.4567   0.7905  309.63  3.4528   
2014-07-21  1.3518  136.97  1.9558  27.468  7.4567   0.7915  309.56  3.4528   

               PLN     RON   ...        ZAR  LVL  EEK  SKK  ISK  CYP  MTL  \
2014-07-25  4.1435  4.3973   ...    14.1489  NaN  NaN  NaN  NaN  NaN  NaN   
2014-07-24  4.1408  4.4068   ...     14.138  NaN  NaN  NaN  NaN  NaN  NaN   
2014-07-23   4.134  4.4228   ...    14.1759  NaN  NaN  NaN  NaN  NaN  NaN   
2014-07-22  4.1473  4.4396   ...    14.3199  NaN  NaN  NaN  NaN  NaN  NaN   
2014-07-21  4.1511  4.4445   ...    14.3647  NaN  NaN  NaN  NaN  NaN  NaN   

            SIT  ROL  TRL  
2014-07-25  NaN  NaN  NaN  
2014-07-24  NaN  NaN  NaN  
2014-07-23  NaN  NaN  NaN  
2014-07-22  NaN  NaN  NaN  
2014-07-21  NaN  NaN  NaN  

[5 rows x 41 columns]

Plotting data

Once you the pandas data frame, using matplot lib, you can easily plot data


In [ ]:
import matplotlib.pyplot as plt

In [7]:
plt.plot(historical_df['USD'])


Out[7]:
[<matplotlib.lines.Line2D at 0x110c2b090>]